import 'package:base_plugin/base_plugin.dart';
import 'package:finance_app/generated/a.dart';
import 'package:finance_app/generated/l10n.dart';
import 'package:finance_app/src/common/app_colors.dart';
import 'package:finance_app/src/common/app_spaces.dart';
import 'package:finance_app/src/entities/ocr_attachment_entity.dart';
import 'package:finance_app/src/widgets/form/form_edit_status_inherited_widget.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';

class SingleFileForm extends StatelessWidget {
  final String file;
  final VoidCallback onAdd;
  final ValueChanged<String> onSelectFile;
  final OcrAttachmentEntity attachment;
  final ValueChanged<OcrAttachmentEntity> onSelectAttachment;
  final VoidCallback onDelete;

  const SingleFileForm(
      {Key key,
      this.file,
      this.onAdd,
      this.attachment,
      this.onSelectFile,
      this.onSelectAttachment,
      this.onDelete})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    bool isEnable = FormEditStatusInheritedWidget.ofEnable(context);
    if (isEnable)
      return Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text(
            S.current.bank_statement,
            style: TextStyle(
              color: aceDarkGrayColor,
              fontSize: getSp(14),
              fontWeight: FontWeight.w400,
              height: 1,
            ),
          ),
          AppSpaces.h15,
          SizedBox(
            width: getDp(94),
            height: getDp(87),
            child: file == null ? _buildAttachAdd() : _buildItems(context),
          )
        ],
      );
    else
      return Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text(
            S.current.bank_statement,
            style: TextStyle(
              color: aceDarkGrayColor,
              fontSize: getSp(14),
              fontWeight: FontWeight.w400,
              height: 1,
            ),
          ),
          AppSpaces.h15,
          if (file != null || attachment != null)
            SizedBox(
              width: getDp(94),
              height: getDp(87),
              child: file == null ? _buildAttachAdd() : _buildItems(context),
            ),
        ],
      );
  }

  Widget _buildItems(BuildContext context) {
    return Stack(
      clipBehavior: Clip.none,
      children: [
        Positioned.fill(
          child: PressedOpacityButton(
            onPressed: onAdd,
            color: aceDarkGrayColor05,
            child: Center(
              child: SvgPicture.asset(
                A.assetsImagesStyleExcel_1,
                width: getDp(40),
                height: getDp(40),
              ),
            ),
          ),
        ),
        Positioned(
            top: -getDp(7),
            right: -getDp(12),
            child: PressedOpacityButton(
              onPressed: onDelete,
              child: SvgPicture.asset(
                A.assetsImagesSettingRemove_1,
                width: getDp(24),
                height: getDp(24),
              ),
            )),
      ],
    );
  }

  Widget _buildAttachAdd() {
    return PressedOpacityButton(
      onPressed: onAdd,
      color: aceDarkGrayColor05,
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Icon(
            CupertinoIcons.link,
            size: getDp(27),
            color: aceBlueColor,
          ),
          SizedBox(
            height: getDp(12),
          ),
          Text(
            S.current.upload,
            style: TextStyle(
              color: aceBlueColor,
              fontSize: getSp(16),
              fontWeight: FontWeight.w700,
              height: 14 / 16,
            ),
          ),
        ],
      ),
    );
  }
}
